package com.lovepick.adapter;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lovepick.bean.FragmentPager;

public class SectionsPagerAdapter extends FragmentPagerAdapter
{
	private List<FragmentPager> mFragmentPagers = null;

	public SectionsPagerAdapter(FragmentManager fm, List<FragmentPager> fragmentPagers)
	{
		super(fm);
		this.mFragmentPagers = fragmentPagers;

	}

	@Override
	public Fragment getItem(int position)
	{
		return mFragmentPagers.get(position).getFragment();
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return mFragmentPagers.size();
	}

	@Override
	public CharSequence getPageTitle(int position)
	{
		return mFragmentPagers.get(position).getTitle();
	}

	public void addItem(FragmentPager pager)
	{
		mFragmentPagers.add(pager);
		notifyDataSetChanged();
	}

	public boolean removeItem(FragmentPager pager)
	{
		boolean b = false;
		if (mFragmentPagers.contains(pager))
		{
			b = mFragmentPagers.remove(pager);
			notifyDataSetChanged();

		}
		return b;
	}

	public void removeItem(int location)
	{
		if (mFragmentPagers.size() > 1)
		{
			mFragmentPagers.remove(location);
			notifyDataSetChanged();
		}
	}

}
